iT邦幫忙

2022 iThome 鐵人賽

DAY 18
0
crop_configs = self._get_crop_configs()
        need_to_update_configs = [
            str(row.id) for row in get_need_to_export_config()
        ]
        for crop_config in crop_configs:
            crop_config_id = crop_config['id']
            if crop_config_id != 'f4f2e9cb-ee3b-4f2c-8eee-2b15ce50cf44':
                continue
            crop_config_category = crop_config['category']
            project_name = crop_config['project_name']
            need_to_export_result = get_need_to_export_results(
                crop_config_id
            )
            self.task_ids = list(set([
                result.crop_task_id for result in need_to_export_result
            ]))
            need_to_export_result_ids = [
                result.crop_result_id for result in need_to_export_result
            ]

            if crop_config_category == CROP_CONFIG_CATEGORY.CUSTOMIZE or crop_config_id not in need_to_update_configs:
                continue

            need_to_add_result_ids = self._get_crop_result_not_in_db(
                need_to_export_result_ids
            )

            need_to_add_result = \
                CropResult.get_crop_result_by_ids(need_to_add_result_ids)
            need_to_add_result_length = len(need_to_add_result_ids)

            need_to_add_crop_task_ids = list(
                set([row.source_id for row in need_to_add_result])
            )
            need_to_export_error = \
                CropError.get_crop_error_by_crop_task_ids(
                    need_to_add_crop_task_ids)

            need_to_add_error_ids = self._get_crop_error_not_in_db(
                need_to_export_error
            )
            need_to_add_error = CropError.get_crop_error_by_ids(
                need_to_add_error_ids)

            crop_exporters = \
                CropExporter.get_crop_exporters_of_crop_config(crop_config_id)

            valid_crop_exporters = list(filter(
                lambda crop_exporter:
                crop_exporter.batch_count + need_to_add_result_length < GOOGLE_SHEET_LIMIT,
                crop_exporters
            ))

            if not valid_crop_exporters:
                crop_exporter = self.create_crop_report(
                    project_name, crop_config_id
                )
                self.create_update_task(project_name, crop_exporter.sheet_id)
                valid_crop_exporters.append(crop_exporter)
            else:
                crop_exporter = valid_crop_exporters[0]

            self.connect_crop_exporter_and_scopes(
                'result', crop_exporter, need_to_add_result
            )

            self.connect_crop_exporter_and_scopes(
                'error', crop_exporter, need_to_add_error
            )

            crop_exporter_id = str(crop_exporter.id)
            record = CropExporter.get(id=crop_exporter_id)
            record.batch_count = crop_exporter.batch_count + need_to_add_result_length
            record.save()

            for crop_exporter in valid_crop_exporters:
                self.update_report(crop_exporter)
                update_crop_task_google_sheet_link(crop_exporter.id)

上一篇
D17-高低階分離
下一篇
D19 - 資源分配
系列文
寫個好的lib大家用吧!那些好用的lib常見的套路與想法25
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言